﻿/// <reference path="jquery-1.4.1.min.js" />
$(document).ready(
    function () {
        //analysisJSON();
        //analysisJSON2();
        analysisJSON3();
        //analysisJSON4();
        //analysisXML();
    }

);

function analysisJSON() {
    //var arr = ["one", "two", "three", "four"];
    var arr = [[1, 4, 5], [4, 6, 6], [7, 20, 9]]
    $.each(arr, function () {
        alert(this);
    });
}

function analysisJSON2() {
    var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]]
    $.each(arr1, function (i, item) {
        alert(item[0]+"-"+item[1]+"-"+item[2]);
    });
}

function analysisJSON3() {
    var obj = { one: 1, two: 2, three: 3, four: 4 };
    alert(obj);
    $.each(obj, function (key, val) {
        alert(obj[key]);
    });

    $.each(obj, function (key, val) {
        alert(key+"--"+val);
    });

    $.each(obj, function (key, val) {
        alert("obj.one:" + obj.one + "--" + "obj.two:" + obj.two + "--" + "obj.three:" + "--" + obj.three + "--" + "obj.four:" + obj.four);
    });
}

function analysisJSON4() {
    var data = [{ "name": "陶国荣",
                  "sex": "男",
                  "email": "tao_guo_rong@163.com"
              },
              { "name": "李世杰",
                  "sex": "男",
                  "email": "lsj6607@126.com"
              }
    ]
              $("#divShow").empty();
              var TempTable = "<table><tr><td>姓名</td><td>性别</td><td>邮箱</td></tr>";
              $.each(data, function (key, val) {
                  TempTable += "<tr><td>"+val.name+"</td><td>"+val.sex+"</td><td>"+val.email+"</td></tr>";

              })
              TempTable += "</table>";
              $("#divShow").html(TempTable);
          }

        function analysisXML() {
            $.ajax({
                url: "AjaxHandler.ashx",
                async: true,
                cached:false,
                data: { s: "s" },
                type: "get",
                dataType: "xml",
                success: function (data) {
                    $("#divShow").empty();
                    var TempTable = "<table><tr><td>姓名</td><td>性别</td><td>邮箱</td></tr>";
                    $(data).find("User").each(function () {
                        var strUser = $(this);
                        TempTable += "<tr><td>" + strUser.find("name").text() + "</td><td>" + strUser.find("sex").text() + "</td><td>" + strUser.find("email").text() + "</td></tr>";
                    })
                    TempTable += "</table>";
                    $("#divShow").html(TempTable);
                }
            }
            )
        }

